﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using HZ.MBSM.DBUtility;
public partial class Agency_Check_BidGood_Child : System.Web.UI.Page,HZ.MBSM.BLL.IPageDescribe 
{
    public string BId;
    protected void Page_Load(object sender, EventArgs e)
    {
        
        System.Collections.Generic.List<HZ.MBSM.DAL.AccountType> _AccountType = new System.Collections.Generic.List<HZ.MBSM.DAL.AccountType>();
        _AccountType.Add(HZ.MBSM.DAL.AccountType.enumBidGoods);
        if (HZ.MBSM.BLL.Login.CheckAssert(_AccountType))
        {
            HZ.MBSM.Model.Account _Account = (HZ.MBSM.Model.Account)Session["Account"];
            
            if (_Account != null)
            {
                Int64 AccountId = SysFun.ToLong(_Account.AccountId);
                if (!IsPostBack)
                {
                    Db db = new Db();
                    string strSql = "select projectid,ProjectMarker,Title from project where accountid in (select accountid_father from dbo.AgencyChild where accountid=" + AccountId.ToString() + ")";
                    System.Data.IDataReader dr = db.DataReader(strSql);
                    listProject.DataSource = dr;
                    listProject.DataTextField = "Title";
                    listProject.DataValueField = "projectid";
                    listProject.DataBind();
                    dr.Close();
                    dr.Dispose();
                    db.Close();
                }
                    string projectid = listProject.SelectedValue;
                    SHowcompany_tb(projectid);
                  
                
                if ( Request.Form["chk"] != null)
                {
                    string _strBidId = Request.Form["chk"].ToString(), _strSub, strSql;
                    _strSub = Request.Form["subPass"];
                    BId = Request.Form["chk"].ToString();
                    if (_strSub == "" || _strSub == null)
                    {
                        _strSub = Request.Form["subNoPass"];
                    }
                    Db db1 = new Db();
                    string atname = _Account.AccountName;
                    //string attype = _Account.Type;
                    if (_strSub=="审核通过")
                    {
                        strSql = "update project_bid set checkstatus=1,memo8='" + atname + "',SHSJ=getdate(),memo9=null where bidid in (" + _strBidId + ")";
                        db1.Command(strSql);
                        HZ.MBSM.BLL.LogManage.RecordLoginDetail(_Account.AccountName, Request.UserHostAddress, "更新", "project_bid", strSql, "../Agency/Check_BidGood_Child.aspx");

                    }
                    else if((_strSub == "审核不通过") && (Session["IsCheck"].ToString()=="1"))
                    {
                        Response.Write("<Script>window.open('BidNoPass.aspx?Bidid=" + BId + "')</Script>");
                    }
                    
                    db1.Close();
                }
                Session["IsCheck"] = "1";
                showGridView();
            }
        }
    }
    private void SHowcompany_tb(string projectid)
    {
        string strSqll = "select distinct AccountId_TB, salername from bidgoods_view where projectid=" + projectid + " order by salername";
        Db dbb = new Db();
        System.Data.IDataReader drr = dbb.DataReader(strSqll);
        Company.DataSource = drr;
        Company.DataTextField = "salername";
        Company.DataValueField = "AccountId_TB";
        Company.DataBind();
        if (Company.Items.Count == 0) return;
        Company.Items.Insert(0, new ListItem("全部", "-1"));
        drr.Close();
        drr.Dispose();
        dbb.Close();
        //txtProductCode.Text = "";
        //txtProductName.Text = "";
        //txtOutlookc.Text = "";
        Company.SelectedValue =null;
        lstCheckStatus.Items.Add("全部");
        lstCheckStatus.Items.Add("未审核");
        lstCheckStatus.Items.Add("审核通过");
        lstCheckStatus.Items.Add("审核未通过");
        lstMemo3.Items.Add("全部");
        lstMemo3.Items.Add("已保存未提交");
        lstMemo3.Items.Add("已提交");
        lstMemo3.Items.Add("已修改");
        Session["IsCheck"] = "1";

    }
    public void showGridView()
    {
        int i = 0;
        string strConditions = fctConditions();
        Db db = new Db();
        DbPage dbPage = new DbPage(db);
        dbPage.Table = "bidgoods_view";                                               //要查询的表明
        dbPage.Key = "bidid";                                               //表的主键    
        dbPage.Where = strConditions;                                           //查询条件    
        dbPage.SelectField = "factoryusercode,MEMO9,memo8,bidid,goodsid,ProductName,Outlookc,factor,Medicinemodel,Unit,ProductCode,salername,factoryname,UserCode_TB,goodsName,case  when CheckStatus is   null then '未审核' when CheckStatus='0' then '未审核'  when CheckStatus='1' then '审核通过' when CheckStatus='2' then '不通过'  when CheckStatus='3' then '废标' when CheckStatus='4' then '超过限价废标' when CheckStatus='5' then '竞价废标' else '未知' end  as CheckStatus,case  when Company_SC_check is   null then '未审核' when Company_SC_check='0' then '未审核'  when Company_SC_check='1' then '审核通过' when Company_SC_check='2' then '不通过' end as Company_SC_check ";//要显示的字段
        dbPage.PageIndex = SysFun.ToInt(Request["CurrentlyPageIndex"]);          //要显示第几页   
        dbPage.PageSize = 20;                                                    //没有显示记录条数   
        dbPage.OrderBy = "productcode,productname,medicinemodel,outlookc,goodsid,Bidid";//排序字段
        System.Text.StringBuilder strHtml = new System.Text.StringBuilder();
        strHtml.Append("<table width='98%' border='0' align='center' cellpadding='2' cellspacing='1' class='table_table'>");
        strHtml.Append("<tr>");
        strHtml.Append("<td class='table_title' nowrap>流水号</td>");
        strHtml.Append("<td class='table_title' nowrap>注册号</td>");
        strHtml.Append("<td class='table_title' nowrap>投标人</td>");
        strHtml.Append("<td class='table_title' nowrap>品目号</td>");
        strHtml.Append("<td class='table_title' nowrap>通用名</td>");
        strHtml.Append("<td class='table_title' nowrap>规格</td>");
        strHtml.Append("<td class='table_title' nowrap>剂型</td>");
        strHtml.Append("<td class='table_title' nowrap>转换系数</td>");
        strHtml.Append("<td class='table_title' nowrap>生产厂家</td>");
        strHtml.Append("<td class='table_title' nowrap>注册号</td>");
        strHtml.Append("<td class='table_title' nowrap>审核状态</td>");
        strHtml.Append("<td class='table_title' nowrap>审核人</td>");
        strHtml.Append("<td class='table_title' nowrap>查看</td>");
        //strHtml.Append("<td class='table_title' nowrap>选择</td>");
        strHtml.Append("</tr>");
        System.Data.IDataReader dr = dbPage.ExecuteReader();

        while (dr.Read())
        {
            string _strCheckStatus = dr["CheckStatus"].ToString();
            if (_strCheckStatus == "不通过")
            {
                strHtml.Append("<tr style='background-color:Yellow'>");
            }
            else
            {
                if (i == 0)
                {
                    strHtml.Append("<tr class='table_td'>");
                    i++;
                }
                else
                {
                    strHtml.Append("<tr class='table_td2'>");
                    i--;
                }
            } strHtml.Append("<td>" + dr["goodsid"].ToString() + "</td>");
            strHtml.Append("<td>" + dr["UserCode_TB"].ToString() +"</td>");
            strHtml.Append("<td><input type='hidden' name='AccountId' value='" + dr["bidid"].ToString() + "'>" + dr["salername"].ToString() + "</td>");
            strHtml.Append("<td>" + dr["ProductCode"].ToString() + "</td>");
            strHtml.Append("<td>" + dr["ProductName"].ToString() + "</td>");
            strHtml.Append("<td>" + dr["Outlookc"].ToString() + "</td>");
            strHtml.Append("<td>" + dr["Medicinemodel"].ToString() + "</td>");
            strHtml.Append("<td>" + dr["factor"].ToString() + "</td>");
            if (dr["Company_SC_check"].ToString() == "审核通过")
            {
                strHtml.Append("<td title='" + dr["Company_SC_check"].ToString() + "' style=' color: #00cc66;' >" + dr["factoryname"].ToString() + "</td>");
            }
            else if (dr["Company_SC_check"].ToString() == "不通过")
            {
                strHtml.Append("<td title='" + dr["Company_SC_check"].ToString() + "' style=' color: #ff0033;'>" + dr["factoryname"].ToString() + "</td>");
            }
            else
            {
                strHtml.Append("<td title='" + dr["Company_SC_check"].ToString() + "'>" + dr["factoryname"].ToString() + "</td>");
            }
            strHtml.Append("<td>" + dr["factoryusercode"].ToString() + "</td>");
            strHtml.Append("<td title='" + dr["MEMO9"].ToString() + "'>" + _strCheckStatus + "</td>");
            strHtml.Append("<td>" + dr["memo8"].ToString() + "</td>");
            strHtml.Append("<td><a target=_blank href='BidGoods_detail.aspx?BidId=" + dr["BidId"].ToString() + "&CheckStatus=" + dr["CheckStatus"].ToString() + "&Id=1&ProjectId=" + listProject.SelectedValue + "'>查看</a></td>");
            //strHtml.Append("<td><input name='chk' type='checkbox' value='" + dr["bidid"].ToString() + "'></td>");
            strHtml.Append("</tr>");
        }
        strHtml.Append("</table>");
        Label1.Text = strHtml.ToString();
       
        //GridView1.DataSource = dr;
        //GridView1.DataBind();
        dr.Close();
        dr.Dispose();
        dbPage.Db.Close();
        db.Close();

        this.DbPageFlip1.DbPage = dbPage;//将数据传给控键



    }

    /// <summary>
    /// 生成查询条件
    /// </summary>
    /// <returns></returns>
    public string fctConditions()
    {
        string strtemp = "", CheckStatus, _SC, _GoodsId, name, outlookc, company, productcode, projectid, CompanyUserCode, scqyzch;
        productcode = txtProductCode.Text.ToString().Trim(); 
        name =txtProductName.Text.ToString().Trim();
        outlookc = txtOutlookc.Text.ToString().Trim();
        CompanyUserCode = txtCompanyUserCode.Text.ToString().Trim();
        company = SysFun.ToTrim(Company.SelectedValue);
        projectid = listProject.SelectedValue;
        strtemp = " projectid=" + projectid + " and";
        CheckStatus = lstCheckStatus.SelectedValue;
        _SC = SysFun.ToTrim(txtSC.Text);
        _GoodsId = SysFun.ToTrim(txtGoodsID.Text);
        scqyzch = SysFun.ToTrim(txtscqyzch.Text);
        switch (CheckStatus)
        {
            case "全部":
                if (chk1.Checked == true)
                {
                    strtemp += " productname+convert(varchar(255),accountid_sc) in (select productname+convert(varchar(255),goods.accountid_sc) as ProductNameAndAccountId_SC from product ,goods,project_bid where product.productid=goods.productid and goods.goodsid=project_bid.goodsid and projectid=" + projectid + "  group by productname+convert(varchar(255),goods.accountid_sc) having max(project_bid.Accountid)<>min(project_bid.Accountid)) and";
                }
                break;
            case "未审核":
                strtemp += " (CheckStatus=0 or CheckStatus is null) and";
                if (chk1.Checked == true)
                {
                    strtemp += " productname+convert(varchar(255),accountid_sc) in (select productname+convert(varchar(255),goods.accountid_sc) as ProductNameAndAccountId_SC from product ,goods,project_bid where product.productid=goods.productid and goods.goodsid=project_bid.goodsid  and (project_bid.CheckStatus=0 or project_bid.CheckStatus is null) and projectid=" + projectid + "  group by productname+convert(varchar(255),goods.accountid_sc) having max(project_bid.Accountid)<>min(project_bid.Accountid)) and";
                }
                break;
            case "审核通过":
                strtemp += " CheckStatus=1 and";
                if (chk1.Checked == true)
                {
                    strtemp += " productname+convert(varchar(255),accountid_sc) in (select productname+convert(varchar(255),goods.accountid_sc) as ProductNameAndAccountId_SC from product ,goods,project_bid where product.productid=goods.productid and goods.goodsid=project_bid.goodsid and  project_bid.CheckStatus=1 and projectid=" + projectid + "  group by productname+convert(varchar(255),goods.accountid_sc) having max(project_bid.Accountid)<>min(project_bid.Accountid)) and";
                }
                break;
            case "审核未通过":
                strtemp += " CheckStatus=2 and";
                if (chk1.Checked == true)
                {
                    strtemp += " productname+convert(varchar(255),accountid_sc) in (select productname+convert(varchar(255),goods.accountid_sc) as ProductNameAndAccountId_SC from product ,goods,project_bid where product.productid=goods.productid and goods.goodsid=project_bid.goodsid and  project_bid.CheckStatus=2 and projectid=" + projectid + "  group by productname+convert(varchar(255),goods.accountid_sc) having max(project_bid.Accountid)<>min(project_bid.Accountid)) and";
                }
                break;
        }

        //提交状态
        string _Memo3 = lstMemo3.SelectedValue;
        switch (_Memo3)
        {
            case "全部":
                break;
            case "已保存未提交":
                strtemp += " Memo3=0 and";
                break;
            case "已提交":
                strtemp += " Memo3=1 and";
                break;
            case "已修改":
                strtemp += " Memo3=2 and";
                break;
        }
        if (CheckBox1.Checked) //因价格原因暂时审核通过的商品
        {
            strtemp += "  beizhu=1 and";
        }
        if (scqyzch != "")
        {
            strtemp += " factoryusercode like '%"+ scqyzch +"%' and";
        }

        if (_GoodsId != "")
        {
            strtemp = strtemp + " GoodsId like '%" + _GoodsId + "%' and";

        }
        if (_SC != "")
        {
            strtemp = strtemp + " factoryname like '%" + _SC + "%' and";

        }
        if (productcode != "")
        {
            strtemp = strtemp + " productcode like '%" + productcode + "%' and";

        }
        if (name != "")
        {
            strtemp += " (ProductName like '%" + name + "%'or SpellingCode like '%" + name + "%') and";
        }
        if (outlookc != "")
        {
            strtemp = strtemp + " outlookc like '%" + outlookc + "%' and";
        }
        if ((company != "-1") && (company!=""))
        {
            strtemp = strtemp + " AccountId_TB=" + company + " and";
        }
        if (CompanyUserCode != "")
        {
            strtemp += " UserCode_TB='" + CompanyUserCode + "' and";
        }

        if (strtemp != "")
        {
            strtemp = "  " + strtemp.Substring(0, strtemp.Length - 3);
        }
        return strtemp;

    }


   



    #region IPageDescribe 成员

    public string Name
    {
        get { return "投标商品审核"; }
    }

    public string Describe
    {
        get { return ""; }
    }

    public string ParentName
    {
        get { return "投标商品审核"; }
    }

    public System.Collections.Generic.List<HZ.MBSM.DAL.AccountType> UseAccountType
    {
        get
        {
            System.Collections.Generic.List<HZ.MBSM.DAL.AccountType> _AccountType = new System.Collections.Generic.List<HZ.MBSM.DAL.AccountType>();
            _AccountType.Add(HZ.MBSM.DAL.AccountType.enumBidGoods);
            return _AccountType;
        }
    }
    #endregion
    protected void Button5_Click(object sender, EventArgs e)
    {

    }
}
